﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CarShop.Domain.Entities;

namespace CarShop.Data.EntityFramework.Mappings
{
    internal class CarConfiguration : EntityBaseConfiguration<Car, int>
    {
        public CarConfiguration()
        {
            Property(c => c.BuildDate).IsRequired();
            Property(c => c.Model).IsRequired();
            Property(c => c.Price).IsRequired();
            Property(c => c.SerialNumber).IsRequired();

            HasRequired(c => c.CarBrand).WithMany(c => c.Cars).HasForeignKey(c => c.CarBrandId);
            HasRequired(c => c.CarType).WithMany(c => c.Cars).HasForeignKey(c => c.CarTypeId);
            HasOptional(c => c.Order)
                .WithMany(o => o.Cars)
                .HasForeignKey(c => c.OrderId);

            HasMany(c => c.Pictures)
                .WithMany()
                .Map(m => m.MapLeftKey("CarId").MapRightKey("PictureId").ToTable("Car_Picture"));

            HasRequired(c => c.CarStatus).WithMany(c => c.Cars).HasForeignKey(c => c.CarTypeId);
        }
    }
}
